<?php if(!defined('APP_ROOT')){exit('error!');}?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $site_title;?></title>
<link type="text/css" href="<?php echo PUBLIC_URL;?>css/font-awesome.min.css" rel="stylesheet">
<link type="text/css" href="<?php echo TEMPLATE_URL;?>style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo PUBLIC_URL;?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo TEMPLATE_URL;?>js/manage.js"></script>
</head>
<body>
<?php include View::getView('header');?>
<?php include View::getView('side');?>
<div id="mainbox">
    <div class="wrapper">
        <div class="main">
            <div class="itembox w100">
                <div class="wrap">
                    <h2><?php echo $page_title;?><span><a href="<?php echo APP_URL.'user/index';?>"><i class="fa fa-reply"></i> 返回用户列表</a></span></h2>
                    <div class="itemmain">
                        <div id="edit_user">
                            <form name="userForm" onsubmit="return postUserForm();">
                                <table width="100%" cellpadding="0" cellspacing="0" class="adm_table">
                                    <tr>
                                        <td width="150">用户名</td>
                                        <td>
                                            <?php if($user['uid']):?>
                                            <?php echo $user['username'];?>
                                            <?php else:?>
                                            <input type="text" name="username" value="<?php echo $user['username'];?>" class="bar bar1">
                                            <?php endif;?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>真实姓名</td>
                                        <td><input type="text" name="nickname" value="<?php echo $user['nickname'];?>" class="bar bar1"></td>
                                    </tr>
                                    <tr>
                                        <td>电话号码</td>
                                        <td><input type="text" name="phone" value="<?php echo $user['phone'];?>" class="bar bar1"></td>
                                    </tr>
                                    <tr>
                                        <td>邮箱地址</td>
                                        <td><input type="text" name="email" value="<?php echo $user['email'];?>" class="bar bar1"></td>
                                    </tr>
                                    <tr>
                                        <td>用户备注</td>
                                        <td><input type="text" name="description" value="<?php echo $user['description'];?>" class="bar bar3"></td>
                                    </tr>
                                    <tr>
                                        <td>密码</td>
                                        <td><input type="password" name="password1" value="" class="bar bar1" <?php if($user['uid']) echo 'placeholder="不修改密码请留空！"';?>></td>
                                    </tr>
                                    <tr>
                                        <td>重复密码</td>
                                        <td><input type="password" name="password2" value="" class="bar bar1"></td>
                                    </tr>
                                    <tr>
                                        <td>用户组</td>
                                        <td>
                                            <input type="radio" name="role" value="user" <?php if($user['role']=='member') echo 'checked="checked"';?> id="role_member"><label for="role_member">普通用户</label>  &nbsp;&nbsp;
                                            <input type="radio" name="role" value="admin" <?php if($user['role']=='admin') echo 'checked="checked"';?> id="role_admin"><label for="role_admin">管理员</lalel>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td style="padding:30px 20px 40px;">
                                            <input type="hidden" name="token" value="<?php echo loginAuth::genToken();?>">
                                            <input type="hidden" name="uid" value="<?php echo $user['uid'];?>">
                                            <input type="hidden" name="action" value="save">
                                            <input type="submit" value="提交保存" class="btn" >
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php include View::getView('footer');?>
    </div>
</div>
<script type="text/javascript">
function postUserForm(){
    var theData = $("form[name=userForm]").serialize();
    $.ajax({
        'type':'post',
        'dataType':'json',
        'url':'<?php echo APP_URL;?>user/handle',
        'data':theData,
        'success':function(data){
            alert(data.msg);
            if(data.result==200){
                location.href= '<?php echo APP_URL;?>user/index';
            }
        }
    });
    return false;
}
</script>
</body>
</html>